package com.wallet.crypto.trustapp.ui.widget.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wallet.crypto.trustapp.R;
import com.wallet.crypto.trustapp.ui.widget.entity.SettingItem;
import com.wallet.crypto.trustapp.ui.widget.holder.SettingHolder;
import com.wallet.crypto.trustapp.ui.widget.holder.SettingLineHolder;

import java.util.ArrayList;

/**
 * Created by lingjianzhong on 2018/5/8.
 */

public class InSettingAdapter extends RecyclerView.Adapter<SettingHolder> implements View.OnClickListener {

    ArrayList<SettingItem> mItems;
    Context mContext;
    LayoutInflater mInflater;

    public InSettingAdapter(Context context, ArrayList<SettingItem> mItems) {
        this.mContext = context;
        this.mItems = mItems;
        this.mInflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public SettingHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = mInflater.inflate(R.layout.item_setting_rev, parent, false);
        itemView.setOnClickListener(this);
        return new SettingHolder(itemView);

    }

    @Override
    public void onBindViewHolder(@NonNull SettingHolder holder, int position) {
        holder.mIcon.setVisibility(View.GONE);
        holder.mTitle.setText(mItems.get(position).getTitle());
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return mItems.size();
    }


    private OnItemClickListener mOnItemClickListener = null;

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null)
            mOnItemClickListener.onItemClick(v, (int) v.getTag());
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public void setmOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }
}
